package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.elder.business.domain.MealRecordsDTO;
import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.business.domain.MealRecords;
import com.elder.business.service.IMealRecordsService;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 膳食记录Controller
 * 
 * @author elder
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/business/mealRecords")
public class MealRecordsController extends BaseController
{
    @Autowired
    private IMealRecordsService mealRecordsService;

    /**
     * 查询膳食记录列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(String elderName,String startTime,String endTime,Integer pageNum,Integer pageSize)
    {
        return mealRecordsService.selectMealRecordsList(elderName,startTime,endTime, pageNum, pageSize);
    }

    /**
     * 导出膳食记录列表
     */
//    @Anonymous
//    @Log(title = "膳食记录", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, MealRecords mealRecords)
//    {
//        List<MealRecords> list = mealRecordsService.selectMealRecordsList(mealRecords);
//        ExcelUtil<MealRecords> util = new ExcelUtil<MealRecords>(MealRecords.class);
//        util.exportExcel(response, list, "膳食记录数据");
//    }

    /**
     * 获取膳食记录详细信息
     */
    @Anonymous
    @GetMapping(value = "/{mealId}")
    public AjaxResult getInfo(@PathVariable("mealId") Long mealId)
    {
        return success(mealRecordsService.selectMealRecordsByMealId(mealId));
    }

    /**
     * 新增膳食记录
     */
    @Anonymous
    @Log(title = "膳食记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MealRecordsDTO mealRecords)
    {
        return toAjax(mealRecordsService.insertMealRecords(mealRecords));
    }

    /**
     * 修改膳食记录
     */
    @Anonymous
    @Log(title = "膳食记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MealRecordsDTO mealRecords)
    {
        return toAjax(mealRecordsService.updateMealRecords(mealRecords));
    }

    /**
     * 删除膳食记录
     */
    @Anonymous
    @Log(title = "膳食记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mealIds}")
    public AjaxResult remove(@PathVariable Long[] mealIds)
    {
        return toAjax(mealRecordsService.deleteMealRecordsByMealIds(mealIds));
    }
}
